package chd.edu.train.business.controller.admin;

import chd.edu.train.business.req.TrainQueryReq;
import chd.edu.train.business.req.TrainSaveReq;
import chd.edu.train.business.resp.TrainQueryResp;
import chd.edu.train.business.service.TrainSeatService;
import chd.edu.train.business.service.TrainService;
import chd.edu.train.common.resp.CommonResp;
import chd.edu.train.common.resp.PageResp;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Zhang Chaoliang
 * create 2023
 */
@RestController
@RequestMapping("/admin/train")
public class TrainAdminController {

    @Resource
    private TrainService trainService;

    @Resource
    private TrainSeatService trainSeatService;


    /**
     * 保存/修改编辑信息
     * @param req
     * @return
     */
    @PostMapping("/save")
    public CommonResp<Object> save(@Valid @RequestBody TrainSaveReq req){
        trainService.save(req);

        return new CommonResp<>();
    }

    /**
     * 保存信息
     * @param req
     * @return
     */
    @GetMapping("/query-list")
    public CommonResp<PageResp<TrainQueryResp>> queryList(@Valid TrainQueryReq req){
        PageResp<TrainQueryResp> list = trainService.queryList(req);

        return new CommonResp<>(list);
    }

    /**
     * 删除信息
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id){
        trainService.delete(id);

        return new CommonResp<>();
    }

    /**
     * 保存信息
     * @return
     */
    @GetMapping("/query-all")
    public CommonResp<List<TrainQueryResp>> queryList(){
        List<TrainQueryResp> list = trainService.queryAll();

        return new CommonResp<>(list);
    }

    @GetMapping("/gen-seat/{trainCode}")
    public CommonResp<Object> genSeat(@PathVariable String trainCode) {
        trainSeatService.genTrainSeat(trainCode);
        return new CommonResp<>();
    }


}
